#-*- coding:UTF-8 -*-

import json

from google.appengine.ext import webapp

from vo.SsqInfo import SsqInfo

'''
客户端接口

'''

'''获取最新开奖信息'''
class SSQLastData(webapp.RequestHandler):
    
    def get(self):
        ssqInfo = None
        q = SsqInfo.all()
        q.order('-issue')
        results = q.fetch(limit=1)
        if len(results) > 0:
            ssqInfo = results[0]
        
        dict = {}
        if ssqInfo is not None:
            dict["kjDate"] = ssqInfo.kjDate
            dict["issue"] = ssqInfo.issue
            dict["red"] = ssqInfo.red
            dict["blue"] = ssqInfo.blue
            dict["ballNum"] = ssqInfo.ballNum
            dict["poolMoneyAmount"] = ssqInfo.poolMoneyAmount
            dict["soldMoneyAmount"] = ssqInfo.soldMoneyAmount
            
            dict["oneMoneyAmount"] = ssqInfo.oneMoneyAmount
            dict["oneBetAmount"] = ssqInfo.oneBetAmount
            dict["twoMoneyAmount"] = ssqInfo.twoMoneyAmount
            dict["twoBetAmount"] = ssqInfo.twoBetAmount
            dict["threeMoneyAmount"] = ssqInfo.threeMoneyAmount
            dict["threeBetAmount"] = ssqInfo.threeBetAmount
            dict["fourMoneyAmount"] = ssqInfo.fourMoneyAmount
            dict["fourBetAmount"] = ssqInfo.fourBetAmount
            dict["fiveMoneyAmount"] = ssqInfo.fiveMoneyAmount
            dict["fiveBetAmount"] = ssqInfo.fiveBetAmount
            dict["sixMoneyAmount"] = ssqInfo.sixMoneyAmount
            dict["sixBetAmount"] = ssqInfo.sixBetAmount
            
        self.response.out.write(json.dumps(dict))

''' 获取历史开奖数据 '''
class SSQHistory(webapp.RequestHandler):
    def get(self):
        beginIssue = None   #起始期号
        pageCount = 20      #分页数量
        
        try:
            beginIssue = self.request.headers['beginIssue']
        except:
            pass
        
        q = SsqInfo.all()
        if beginIssue is not None :
            q.filter('issue <', beginIssue)
        q.order('-issue')
        results = q.fetch(limit=pageCount)
        
        resultArray = []
        if len(results) > 0 :
            for ssqInfo in results :
                dict = {}
                dict["kjDate"] = ssqInfo.kjDate
                dict["issue"] = ssqInfo.issue
                dict["red"] = ssqInfo.red
                dict["blue"] = ssqInfo.blue
                dict["ballNum"] = ssqInfo.ballNum
                dict["poolMoneyAmount"] = ssqInfo.poolMoneyAmount
                dict["soldMoneyAmount"] = ssqInfo.soldMoneyAmount
                
                dict["oneMoneyAmount"] = ssqInfo.oneMoneyAmount
                dict["oneBetAmount"] = ssqInfo.oneBetAmount
                dict["twoMoneyAmount"] = ssqInfo.twoMoneyAmount
                dict["twoBetAmount"] = ssqInfo.twoBetAmount
                dict["threeMoneyAmount"] = ssqInfo.threeMoneyAmount
                dict["threeBetAmount"] = ssqInfo.threeBetAmount
                dict["fourMoneyAmount"] = ssqInfo.fourMoneyAmount
                dict["fourBetAmount"] = ssqInfo.fourBetAmount
                dict["fiveMoneyAmount"] = ssqInfo.fiveMoneyAmount
                dict["fiveBetAmount"] = ssqInfo.fiveBetAmount
                dict["sixMoneyAmount"] = ssqInfo.sixMoneyAmount
                dict["sixBetAmount"] = ssqInfo.sixBetAmount
        
                resultArray.append(dict)
                
        self.response.out.write(json.dumps(resultArray))
        
        